#region License, Terms and Conditions
//
// Prawks - Copyright (c) 2007 Atif Aziz. All rights reserved.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
//
#endregion

namespace Prawks.CodeProvisioningCompiler
{
    using Utilities;
    
    using StringWriter = System.IO.StringWriter;

    sealed class CompilerOptions
    {
        [ DefaultCommandLineArgument(CommandLineArgumentType.Required) ]
        public string BaseAssemblyPath = null;
        [ CommandLineArgument(CommandLineArgumentType.AtMostOnce, LongName = "OutputAssembly", ShortName = "oa") ]
        public string OutputAssemblyName = string.Empty;
        [ CommandLineArgument(CommandLineArgumentType.AtMostOnce, ShortName = "verify") ]
        public bool VerifyAssembly = true;
        [ CommandLineArgument(CommandLineArgumentType.AtMostOnce, ShortName = "verifier") ]
        public string VerifierPath = "peverify.exe";
        [ CommandLineArgument(CommandLineArgumentType.AtMostOnce, ShortName = "verbose") ]
        public bool VerboseReporting = false;
        [ CommandLineArgument(CommandLineArgumentType.AtMostOnce, ShortName = "odir") ]
        public string OutputDirectory = string.Empty;
        [ CommandLineArgument(CommandLineArgumentType.AtMostOnce, ShortName = "v") ]
        public string Version = string.Empty;
        [ CommandLineArgument(CommandLineArgumentType.AtMostOnce, ShortName = "c") ]
        public string Culture = string.Empty;
        [ CommandLineArgument(CommandLineArgumentType.AtMostOnce, ShortName = "keyf") ]
        public string KeyFile = string.Empty;
        [ CommandLineArgument(CommandLineArgumentType.AtMostOnce, ShortName = "keyn") ]
        public string KeyName = string.Empty;

        public static CompilerOptions ParseFromArgs(string[] args)
        {
            CompilerOptions options = new CompilerOptions();
            StringWriter parseErrorWriter = new StringWriter();

            if (!Utility.ParseCommandLineArguments(args, options, new ErrorReporter(parseErrorWriter.WriteLine)))
                throw new ProgramException(parseErrorWriter.GetStringBuilder().ToString());

            return options;
        }

        public static void ShowCommandLineUsage()
        {
            Utility.WriteCommandLineArgumentsUsage(typeof(CompilerOptions));
        }
    }
}
